package com.sxkj.web.controller.api;

import com.qiniu.util.Auth;
import com.sxkj.common.response.ResponseResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/qiniu")
//@ConfigurationProperties(prefix = "spring.qiniu")
//@Configuration
public class QiniuApiController {

    @Value("${qiniu.accessKey}")
    private String accessKey;

    @Value("${qiniu.secretKey}")
    private String secretKey;

    @Value("${qiniu.bucket}")
    private String bucket;

    /**
     * @author Zhang Xingliang
     * @description 获取七牛云文件上传token
     * @date 14:19 2019/6/28
     * @params []
     * @return com.thinkgem.jeesite.common.persistence.ResponseResult
     **/
    @RequestMapping(value = "/getToken" )
    public ResponseResult getQiniuToken(){
        Auth auth = Auth.create(this.accessKey, this.secretKey);
        String upToken = auth.uploadToken( this.bucket);
        Map<String,String> map = new HashMap<>();
        map.put("token",upToken);
        map.put("expires","");
        return ResponseResult.success(map);
    }

    /**
     * @author Zhang Xingliang
     * @description 删除资源
     * @date 11:31 2019/12/25
     * @param map
     * @return com.sxkj.common.response.ResponseResult
     **/
    @RequestMapping(value = "/delete" )
    public ResponseResult delete(@RequestBody Map<String,String> map){
        map.get("path");
        map.put("expires","");
        return ResponseResult.success(map);
    }
}
